package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.pt.MallPtUsers;
import com.tencreat.service.pt.IMallPtUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 拼团详情Controller
 *
 * @author tencreat
 * @date 2021-11-08
 */
@Api(tags="拼团详情api")
//@RestController
@RequestMapping("/system/users")
public class MallPtUsersController extends BaseController {
    //@Autowired
    private IMallPtUsersService mallPtUsersService;

    /**
     * 查询拼团详情列表
     */
    @ApiOperation(value="查询拼团详情列表")
    @PreAuthorize("@ss.hasPermi('system:users:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtUsers>> list(@RequestBody  MallPtUsers mallPtUsers) {
        QueryWrapper<MallPtUsers> wrapper = Wrappers.query(mallPtUsers);
        Page<MallPtUsers> page =  new Page<>(mallPtUsers.getPageNum(), mallPtUsers.getPageSize());
        return HttpResult.ok(mallPtUsersService.page(page, wrapper));
    }

    /**
     * 导出拼团详情列表
     */
    @ApiOperation(value="导出拼团详情列表")
    @PreAuthorize("@ss.hasPermi('system:users:export')")
    @Log(title = "拼团详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtUsers mallPtUsers) {
        List<MallPtUsers> list = mallPtUsersService.selectMallPtUsersList(mallPtUsers);
        ExcelUtil<MallPtUsers> util = new ExcelUtil<MallPtUsers>(MallPtUsers.class);
        return util.exportExcel(list, "users");
    }

    /**
     * 获取拼团详情详细信息
     */
    @ApiOperation(value="获取拼团详情详细信息")
    @PreAuthorize("@ss.hasPermi('system:users:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtUsers> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallPtUsersService.selectMallPtUsersById(id));
    }

    /**
     * 新增拼团详情
     */
    @ApiOperation(value="新增拼团详情")
    @PreAuthorize("@ss.hasPermi('system:users:add')")
    @Log(title = "拼团详情", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPtUsers mallPtUsers) {
        return to(mallPtUsersService.insertMallPtUsers(mallPtUsers));
    }

    /**
     * 修改拼团详情
     */
    @ApiOperation(value="修改拼团详情")
    @PreAuthorize("@ss.hasPermi('system:users:edit')")
    @Log(title = "拼团详情", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtUsers mallPtUsers) {
        return to(mallPtUsersService.updateMallPtUsers(mallPtUsers));
    }

    /**
     * 删除拼团详情
     */
    @ApiOperation(value="删除拼团详情")
    @PreAuthorize("@ss.hasPermi('system:users:remove')")
    @Log(title = "拼团详情", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPtUsersService.deleteMallPtUsersByIds(ids));
    }
}
